package test.testDB;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;

class DatabaseUtils {
    private static final String URL = "jdbc:mysql://localhost:3306/mall";
    private static final String USER = "root";
    private static final String PASSWORD = "lin1234567";

    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(URL, USER, PASSWORD);
    }
}


public class testDButils {
    public static void main(String[] args) {
        QueryRunner queryRunner = new QueryRunner();
        String sql = "SELECT * FROM users"; // 替换为你的表名
        try (Connection connection = DatabaseUtils.getConnection()) {
            List<User> users = queryRunner.query(connection, sql, new BeanListHandler<>(User.class));
            System.out.println(users.toString());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
